PowerTCP Emulation for .NET
Emulation Overview



This topic discusses basic concepts related to VT Emulation. See the Assembly Overview for more information on PowerTCP Emulation for .NET use.


Keymapping

The Vt control uses a default key mapping that is close to the keyboard layout of a VT terminal. For example, the PF1 key on the VT is the top left key on the numeric keypad, so the NUMLOCK key on the PC numeric keypad is mapped to the PF1 function key. The following table summarizes the default keyboard mappings:

VT Key PC Key
Find INSERT
InsertHere HOME
Remove PAGE UP
Select DELETE
PrevScreen END
NextScreen PAGE DOWN
PF1 NUMLOCK
PF2 / (on numeric keypad)
PF3 · (on numeric keypad)
PF4 - (on numeric keypad)
, (comma) + (on numeric keypad)
- (minus) + (on numeric keypad)
Enter ENTER (on numeric keypad)
F6–F10 (w/ Shift for user-defined keys) F6 through F10 (w/ CTRL for user-defined keys)
F11–F20 (w/ Shift for user-defined keys) SHIFT+F through Shift+F10 (w/ CTRL for user-defined keys)
Help F11
Do F12

To modify these default mappings, set the Handled argument in the KeyDown event handler to true (preventing further key events) and send substitute data directly out the communications channel. See the KeyDown help page for a detailed example. To easily generate the bytes that represent the various keys, use the VtKey enumeration with Vt.MapVtKey().

Detailed VT Cell.Character String Tables

The following tables list character strings generated by the VT. The reader may wish to obtain more complete programming information directly from Digital Equipment Corporation. To use the below tables with our component: for example, F6 is defined as "CSI 1 7 ~", in order to send this to a server under 8-bit mode, Telnet.Send("\x9b" + "17~"), or generate the bytes using Vt.MapVtKey().

Control Sequence 7-bit Mode 8-bit Mode
ESC 0x1b 0x1b
CSI ESC [ 0x9b
SS3 ESC O 0x8f

 

VT/IBM Main Keypad Function Keys Code Transmitted
BACKSPACE DEL character
TAB HT character
RETURN CR or CRLF depending upon the NewLine property
CTRL, Lock, SHIFT Does not send a code
SPACEBAR SP character

 

VT Edit Key IBM Edit Key VT 220/320 Code VT 100/52 Code
Find INSERT CSI 1 ~ None
Insert Here HOME CSI 2 ~ None
Remove PAGE UP CSI 3 ~ None
Select DELETE CSI 4 ~ None
Prev Screen END CSI 5 ~ None
Next Screen PAGE DOWN CSI 6 ~ None

 

VT/IBM Cursor Keys VT100/220/320 Code Normal Cursor Key Mode VT100/220/320 Code Application Cursor Key Mode VT52 Code Normal Cursor Key Mode VT52 Code Application Cursor Key Mode
UP ARROW CSI A SS3 A ESC A ESC A
DOWN ARROW CSI B SS3 B ESC B ESC B
RIGHT ARROW CSI C SS3 C ESC C ESC C
LEFT ARROW CSI D SS3 D ESC D ESC D

 

VT Aux Keypad IBM Aux KeyPad VT100/220/ 320 Code Numeric Keypad Mode VT100/220/ 320 Code Application Keypad Mode VT52 Code Numeric Keypad Mode VT52 Code Application Keypad Mode
0 0 0 SS3 p 0 ESC ? p
  1 1 SS3 q 1 ESC ? q
  2 2 SS3 r 2 ESC ? r
  3 3 SS3 s 3 ESC ? s
  4 4 SS3 t 4 ESC ? t
  5 5 SS3 u 5 ESC ? u
  6 6 SS3 v 6 ESC ? v
  7 7 SS3 w 7 ESC ? w
  8 8 SS3 x 8 ESC ? x
  9 9 SS3 y 9 ESC ? y
- Ctrl + "+" - (minus) SS3 m - ESC ? m
, + , (comma) SS3 l , ESC ? l
. . . (period) SS3 n . ESC ? n
Enter Enter CR or CR/LF SS3 M CR or CR/LF ESC ? M
PF1 NumLock SS3 P SS3 P ESC P ESC P
PF2 / SS3 Q SS3 Q ESC Q ESC Q
PF3   SS3 R SS3 R ESC R ESC R
PF4 - SS3 S SS3 S ESC S ESC S

 

VT Function Keys IBM Function Keys VT220/320 Code VT100/52 Code
Hold Screen F1 (none) (none)
Print Screen F2 (none) (none)
Set-up F3 (none) (none)
Data/Talk F4 (none) (none)
Break F5 (none) (none)
F6 F6 CSI 1 7 ~ (none)
F7 F7 CSI 1 8 ~ (none)
F8 F8 CSI 1 9 ~ (none)
F9 F9 CSI 2 0 ~ (none)
F10 F10 CSI 2 1 ~ (none)
F11 (ESC) <shift> F1 CSI 2 3 ~ ESC
F12 (BS) <shift> F2 CSI 2 4 ~ BS
F13 (LF) <shift> F3 CSI 2 5 ~ LF
F14 <shift> F4 CSI 2 6 ~ (none)
Help F11 CSI 2 8 ~ (none)
Do F12 CSI 2 9 ~ (none)
F17 <shift> F7 CSI 3 1 ~ (none)
F18 <shift> F8 CSI 3 2 ~ (none)
F19 <shift> F9 CSI 3 3 ~ (none)
F20 <shift> F10 CSI 3 4 ~ (none)


Screen Scraping

Screen scraping is the act of reading data from a terminal display so that it may be used programatically. VT data is decorated with escape character sequences that define visual representation (font color, style, etc.). Often data must be extracted from these sequences, and PowerTCP Emulation for .NET provides several mechanisms for doing so.

Data written to the Vt control (for example, during a Telnet session), is available for scraping. The Vt control includes three methods for scraping the display - ScrapeText, ScrapeHtml and ScrapeCells.  Each of these methods includes two overloads; one with offset and count parameters, and one with row, column and count parameters.  These parameters are 0-based. 

ScrapeText simply returns data without escape characters. 

ScrapeHtml returns HTML data without escape characters. Escape sequences are substituted for HTML tags where appropriate.

ScrapeCells returns an array of Cell objects.  Each Cell object contains character, colors and style information.

Dynamically create the Vt control in code when the visible display is not required.



Resizing

Resizing techniques can be used to ensure that the contents of the visible window are displayed at all times. There are two resizing scenarios. First, the display is resized to accommodate the selected font. Second, the font is resized to accommodate the size of the display.

Set the Height and Width of the Vt control's Size property to resize the display when the font changes.  Alternatively, if the Vt control is docked to a container, set the container's Height and Width.  In the following example, the control is docked to a form and resized (C# and VB code snippets follow):

C# Copy Code

private void doResize()
{
    //Resize form based on size of font
    this.Height (vt1.Rows * vt1.CellSize.Height) + vt1.Padding.Top +
       (this.Height - vt1.Height);
    this.Width (vt1.Columns * vt1.CellSize.Width) + vt1.Padding.Horizontal +
       SystemInformation.VerticalScrollBarWidth + (this.Width - vt1.Width);
}

Visual Basic Copy Code

Private Sub doResize()
    'Resize form based on size of font
    Me.Height (vt1.Rows * vt1.CellSize.Height) + vt1.Padding.Top + _
        (Me.Height - vt1.Height)
    Me.Width (vt1.Columns * vt1.CellSize.Width) + vt1.Padding.Horizontal + _
        SystemInformation.VerticalScrollBarWidth + (Me.Width - vt1.Width)
End Sub

To resize the font when the size of the display changes, set the Font property in the control's Resize event handler.  For example (C# and VB code snippets follow):

C# Copy Code

private void vt1_Resize(object sender, EventArgs e)
{
   //Adjust the Font Size when the display height is resized
   if (mnuOptionsAutoResize.Checked)
   {
      Graphics g CreateGraphics();
      float cellSize ((vt1.Size.Height - vt1.Padding.Vertical) / vt1.Rows);
      float fontSize 6//min font size         
      SizeF s = new SizeF();
      do
      {
         fontSize +(float).25;
         Font f = new Font(vt1.Font.Name, fontSize, vt1.Font.Style);
         s g.MeasureString("w", f, 1000, StringFormat.GenericTypographic);
      } while (s.Height + 1.> cellSize);
      vt1.Font = new Font(vt1.Font.Name, fontSize, vt1.Font.Style);
      vt1.AutoScrollRowPosition = vt1.BufferRows + vt1.Rows;
   }
}

Visual Basic Copy Code

Private Sub vt1_Resize(ByVal sender As ObjectByVal As EventArgs)
    'Adjust the Font Size when the display height is resized
    If mnuOptionsAutoResize.Checked Then
        Dim As Graphics CreateGraphics()
        Dim cellSize As Single = ((vt1.Size.Height - vt1.Padding.Vertical) / vt1.Rows)
        Dim fontSize As Single = 6 'min font size
        Dim As SizeF = New SizeF()
        Do
            fontSize += CSng(0.25)
            Dim As Font = New Font(vt1.Font.Name, fontSize, vt1.Font.Style)
            s g.MeasureString("w", f, 1000, StringFormat.GenericTypographic)
        Loop While s.Height + 1.< cellSize
        vt1.Font = New Font(vt1.Font.Name, fontSize, vt1.Font.Style)
        vt1.AutoScrollRowPosition = vt1.BufferRows + vt1.Rows;
    End If
End Sub

See Also

Reference


PowerTCP Emulation for .NET Documentation Version 4.7
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic